package com.example.foldertreeview;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesUtils {
    private static SharedPreferences setting = null;
    private static SharedPreferences.Editor editor = null;

    /**
     * 保存用户名、电话号码
     * @param context
     * @param userName
     * @param userPhone
     * @return
     */
    public static boolean setUserAndPhone(Context context , String userName , String userPhone){
        setting = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
        editor = setting.edit();
        editor.putString("userName",userName);
        editor.putString("userPhone",userPhone);
        boolean flag = editor.commit();
        return flag;
    }

    /**
     * 获取用户名
     * @param context
     * @return
     */
    public static String getUserName(Context context ){
        setting = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
        String user = setting.getString("userName","");
        return user;
    }

    /**
     * 获取电话
     * @param context
     * @return
     */
    public static String getUserPhone(Context context){
        setting = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
        String phone = setting.getString("userPhone","");
        return phone;
    }

    /**
     * 设置 电话录音存储路径
     * @param context
     * @param callRecordPath
     * @return
     */
    public static boolean setCallRecordPath(Context context , String callRecordPath){
        setting = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
        editor = setting.edit();
        editor.putString("recordPath",callRecordPath);
        boolean flag = editor.commit();
        return flag;
    }

    /**
     * 获取电话录音默认存储路径
     * @param context
     * @return
     */
    public static String getCallRecordPath(Context context){
        setting = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
        String path = setting.getString("recordPath","none");
        return path;
    }

}
